<template>
  <!-- hidden PageHeaderWrapper title demo -->
    <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="用户名"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'username',
              {rules: [{ required: true, message: '请输入用户名' }]}
            ]"
            name="username"
            placeholder="请输入用户名" />
        </a-form-item>
        
        <a-form-item
          label="密码"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
        
            <a-input-password v-decorator="[
              'password',
              {rules: [{ required: true, message: '请输入密码' }]}
            ]" />
        </a-form-item>
         <a-form-item
          :wrapperCol="{ span: 24 }"
          style="text-align: center"
        >
          <a-button htmlType="submit" type="primary">登录</a-button>
         </a-form-item>
      </a-form>
    </a-card>
</template>

<script>
import { getToken,validateAndGet } from '@/api/jfcloud'

export default {
  name: 'BaseForm',
  data () {
    return {
      form: this.$form.createForm(this)
    }
  },
  methods: {
    // handler
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values)
          getToken(values)
            .then(res => {
              if(res.status == '1'){
                this.$message.success('登录成功')
                localStorage.setItem('jfcloud-token',JSON.stringify(res.datas)) 
                validateAndGet({token:res.datas}).then(
                  res => {
                    localStorage.setItem('jfcloud-user',JSON.stringify(res.datas)) 
                    //this.$router.push({path:'/dashboard/secondKill',query: {id:'1'}})
                    this.$router.go(0)
                  }
                )
              }else{
                this.$message.error(res.meta)
              }
          })
        }
      })
    }
  }
}
</script>
